import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_applearnprogrom/main.dart';

class Global {
  static Global _instance;
  Dio dio;
  String token;
  Map user;

  static Global GetInstance() {
    if (_instance == null) _instance = new Global();
    return _instance;
  }

  Global() {
    dio.options = BaseOptions(
      baseUrl: "https://zxw.td0f7.cn/",
      // baseUrl: "http://localhost:8080/",
      connectTimeout: 5000,
//      sendTimeout: 5000,
      receiveTimeout: 5000,
//      contentType: Headers.formUrlEncodedContentType,
      responseType: ResponseType.json,
    );
    dio.interceptors.add(InterceptorsWrapper(
        onRequest:(RequestOptions options){
          return  options;
        },
        onResponse:(Response response) {
        // 在返回响应数据之前做一些预处理
        return response; // continue
    },
        onError: (DioError e) {
          // 当请求失败时做一些预处理
          return e;//continue
        }
    ));
    dio.interceptors.add(InterceptorsWrapper(
//      onRequest: (options, handler) {
//        return handler.next(options); //continue
//      },

//      onResponse: (response, handler) {
//        return handler.next(response); // continue
//      },

//      onError: (DioError e, handler) {
//        print(e.toString());
//        String msg = "";
//        if (e.type == DioErrorType.CONNECT_TIMEOUT) {
//          msg = "连接超时错误";
//        } else {
//          msg = "接口错误！";
//        }
//      },
    )
    );
  }
}
